<?php
/**
 * 到站代码
 *
 *
 */
class Code_destination_site_model extends Model
{

    var $id;
    
	var $name;

 
	

	function __construct()
    {
        parent::Model();
    }

	// --------------------------------------------------------------------

    /**
	 * load by id
	 *
	 *
	 */	
    function load($id)
    {
        if (!$id){
            return array();
        }

        $query = $this->db->get_where('code_destination_site',array('id' => $id));

        if ($row = $query->row_array()){
            return $row;
        }

        return array();
    }

	// --------------------------------------------------------------------

    /**
	 * 创建
	 *
	 *
	 */	
    function create()
    { 
	 
        $this->db->set('name', $this->name);
        $this->db->set('id', $this->id);	 
              
        return $this->db->insert('code_destination_site');
    }

	// --------------------------------------------------------------------

    /**
	 * 结果集
	 *
	 *
	 */	
    function find_destination_sites()
	{
        $query = $this->db->get('code_destination_site');
        $rows = array();
        foreach ($query->result_array() as $row){          
 
			$rows[$row['id']] = $row;
        }
		
        return $rows;
	}

    // --------------------------------------------------------------------

    /**
	 * 更新
	 *
	 *
	 */	
    function update($id)
    {
        
        $this->db->set('name', $this->name);
		 
        $this->db->where('id', $id);
        return $this->db->update('code_destination_site');
    }
       
 
    // --------------------------------------------------------------------

    /**
	 * 删除
	 *
	 *
	 */	
    function delete($id)
    {        
		$this->db->where('id', $id);

        return $this->db->delete('code_destination_site'); 
    }

    // --------------------------------------------------------------------

    /**
	 * 获取最新添加的数据
	 *
	 *
	 */
	function get_newly_one()
    {
        $this->db->from('code_destination_site');
        $this->db->order_by("id", "desc");
        $this->db->limit('1');
        $query =  $this->db->get();
        return $query->row_array();
    }

    function get_all()
    {
    	$query = $this->db->get('code_destination_site');
    	$rows = array();
    	foreach ($query->result_array() as $row){
    		$rows[$row['id']] = $row;
    	}
    	return $rows;
    }
   
    
    
}